﻿using System.Configuration;

namespace SalesPages.Service.Cache.Redis
{
    public sealed class RedisConfigInfo : ConfigurationSection
    {
        public static RedisConfigInfo GetConfig()
        {
            RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection("RedisConfig");
            return section;
        }

        public static RedisConfigInfo GetConfig(string sectionName)
        {
            RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection("RedisConfig");
            if (section == null)
                throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
            return section;
        }
        /// <summary>
        /// 可写的Redis链接地址
        /// </summary>
        [ConfigurationProperty("ServerList", IsRequired = false)]
        public string ServerList
        {
            get
            {
                return (string)base["ServerList"]; 
            }
            set
            {
                base["ServerList"] = value;
            }
        }

        [ConfigurationProperty("ConnectRetry", IsRequired = false, DefaultValue = 3)]
        public int ConnectRetry
        {
            get
            {
                return (int)base["ConnectRetry"];
            }
            set
            {
                base["ConnectRetry"] = value;
            }
        }

        [ConfigurationProperty("ConnectTimeout", IsRequired = false,DefaultValue =1000)]
        public  int ConnectTimeout
        {
            get
            {
                return (int)base["ConnectTimeout"];
            }
            set
            {
                base["ConnectTimeout"] = value;
            }
        }

        [ConfigurationProperty("PreserveAsyncOrder", IsRequired = false)]
        public  bool PreserveAsyncOrder
        {
            get
            {
                return (bool)base["PreserveAsyncOrder"];
            }
            set
            {
                base["PreserveAsyncOrder"] = value;
            }
        }
        /// <summary>
        /// redis默认DB，默认为0
        /// </summary>
        [ConfigurationProperty("DefaultDB", IsRequired = false, DefaultValue = 0)]
        public int DefaultDB
        {
            get
            {
                return (int)base["DefaultDB"];
            }
            set
            {
                base["DefaultDB"] = value;
            }
        }        


    }
}
